<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>赎回申请</title>
<jsp:include page="../../import.jsp" flush="true" />
<jsp:include page="../assParking/assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->
    <script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
    <jsp:include page="../assCommFilesUpload.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<div id="pageInTab" class="pageInTab">
				<!-- 页签1：赎回申请 -->
				<div tabid="tabA" title="赎回申请" lselected="true">
					<form id="redeemCar">
						<div class="fieldset1 tabel_col clearFix">
							<div class="fieldBox col_33">
								<div class="label">申请人</div>
				                <div class="field">
				                    <span id="applyNm" name="applyNm">${applyNm}</span>
				                </div>
							</div>
				            <div class="fieldBox col_33">
								<div class="label">申请时间</div>
								<div class="field">
									<span id="applyDt" name="applyDt">${sysDate}</span>
								</div>
							</div>
				            <div class="fieldBox col_33">
								<div class="label">拖车标记</div>
								<div class="field">
									<span id="backedFlagCd" name="backedFlagCd">${backedFlagCd}</span>
								</div>
							</div>
							<div class="fieldBox col_33">
								<div class="label">赎回方式</div>
								<div class="field">
									<select name="redeemTypeCd" id="redeemTypeCd" ligerui="width: 160" onchange="changeFileGrid()">
										<option value=" " selected>请选择</option>
										<c:forEach items="${redeemTypeList }" var="redeem">
											<option value="${redeem.key }">${redeem.value }</option>
										</c:forEach>
									</select>
								</div>
							</div>
				            <div class="fieldBox col_33">
								<div class="label">赎回人姓名</div>
								<div class="field">
									<input type="text" id="cstNm" name="cstNm" class="ui-textbox" ligerui="width: 160" value="${cstNm}" readonly>
								</div>
							</div>
							<div class="fieldBox col_33">
								<div class="label">赎回地点</div>
								<div class="field">
									<input type="text" id="redeemAddr" name="redeemAddr" class="ui-textbox" ligerui="width: 160" value="">
								</div>
							</div>
							<div class="fieldBox col_33">
								<div class="label">预计赎回时间</div>
								<div class="field">
									<input type="text" id="redeemTm" name="redeemTm" class="ui-datepicker" ligerui="width: 160" value="">
								</div>
							</div>
				            <div class="fieldBox col_33">
								<div class="label">GPS是否在线</div>
								<div class="field">
									<select name="isOnline" id="isOnline" ligerui="width: 160">
										<option value=" " selected>请选择</option>
										<option value="1">是</option>
										<option value="0">否</option>
									</select>
								</div>
							</div>
							<!-- 汽车金融事业部：可编辑风险保证金 -->
							<c:if test="${buOrgCd == 'ZK' || buOrgCd == 'KY' || buOrgCd == 'CA'}">
								<div class="fieldBox col_33">
									<div class="label">风险保证金1(元)</div>
									<div class="field"></div>
								</div>
							</c:if>
							<div class="fieldBox col_33">
								<div class="label">赎回逾期租金(元)</div>
								<div class="field">
									<c:if test="${buOrgCd == 'ZK' || buOrgCd == 'KY'}">
										<input type="text" id="overdueAmt" name="overdueAmt" class="ui-textbox" ligerui="width: 160" value="" readonly>
									</c:if>
									<c:if test="${buOrgCd == 'CA'}">
										<input type="text" id="overdueAmt" name="overdueAmt" class="ui-textbox" ligerui="width: 160" validate="{number:true}" value="" onchange="planRedeemMoney()">
									</c:if>
								</div>
							</div>
				            <div class="fieldBox col_33">
								<div class="label">赎回罚息(元)</div>
								<div class="field">
									<c:if test="${buOrgCd == 'ZK' || buOrgCd == 'KY'}">
										<input type="text" id="interestAmt" name="interestAmt" class="ui-textbox" ligerui="width: 160" value="" readonly>
									</c:if>
									<c:if test="${buOrgCd == 'CA'}">
										<input type="text" id="interestAmt" name="interestAmt" class="ui-textbox" ligerui="width: 160" validate="{number:true}" value="" onchange="planRedeemMoney()">
									</c:if>
								</div>
							</div>
							<div class="fieldBox col_33">
								<div class="label">应收款金额(元)</div>
								<div class="field">
									<input type="text" id="receivableAmt" name="receivableAmt" class="ui-textbox" ligerui="width: 160" value="" readonly>
								</div>
							</div>
                            <div class="fieldBox col_33">
                                <div class="label">赎回方</div>
                                <div class="field">
                                    <select name="redeemWayCd" id="redeemWayCd" validate="{required:true, select:true}">
                                        <option value=" " selected="selected" >--请选择--</option>
                                        <c:forEach items="${redeemWayList}" var="redeemWayCd">
                                            <option value="${redeemWayCd.key}">${redeemWayCd.value}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
							<!-- 实际支付拖车费用-只做显示不保存到赎回表里 -->
							<c:if test="${buOrgCd == 'ZK' || buOrgCd == 'KY'}">
					            <div class="fieldBox col_33">
									<div class="label">实际付款金额(元)</div>
									<div class="field">
										<input type="text" id="actPayBackAmt" name="actPayBackAmt" class="ui-textbox" ligerui="width: 160" value="${actPayAmt }" readonly>
									</div>
								</div>
								<div class="fieldBox col_33">
									<div class="label">含小贷保底价合计(元)</div>
									<div class="field">${baseAllAmt/100}</div>
								</div>
					            <div class="fieldBox col_33">
									<div class="label"></div>
									<div class="field"></div>
								</div>
							</c:if>
							<!-- 赎回信息 -->
				            <div class="fieldBox col_100">
								<div class="label">赎回说明</div>
								<div class="field">
									<textarea name="redeemDesc" id="redeemDesc" rows="3" class="l-textarea" style="width:98%" value="" ></textarea>
								</div>
							</div>
                            <!-- 上传附件 -->
                            <div class="fieldBox col_100">
                                <div class="label">附件上传</div>
                                <div class="fieldset1 tabel_col clearFix">
                                    <div class="sqPanel_body">
                                        <div id="redeemFileGrid" class="sq-grid"></div>
                                    </div>
                                </div>
                            </div>
							<!-- 隐藏支付表主键、支付表号 -->
			                <div class="fieldBox col_100" style="display:none;">
			                    <div class="field">
			                         <input name="tcMasterId" id="tcMasterId" type="text" class="ui-textbox" value="${tcMasterId}">
			                         <input name="tcDetailId" id="tcDetailId" type="text" class="ui-textbox" value="${tcDetailId}">
			                         <input name="paySchId" id="paySchId" type="text" class="ui-textbox" value="${paySchId}">
                                     <input name="enabledPaySchId" id="enabledPaySchId" type="text" class="ui-textbox" value="${enabledPaySchId}">
                                     <input name="enabledPaySchNo" id="enabledPaySchNo" type="text" class="ui-textbox" value="${enabledPaySchNo}">
	                         		 <input name="prjPrdDtlId" id="prjPrdDtlId" type="text" class="ui-textbox" value="${prjPrdDtlId}">
			                         <input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
			                         <input name="buOrgCd" id="buOrgCd" type="text" class="ui-textbox" value="${buOrgCd}">
			                         <input name="redeem_Id" id="redeem_Id" type="text" class="ui-textbox" value="${redeem_Id}">
			                         <!-- 以下参数为流程需要 -->
			                         <input name="prjId" id="prjId" type="text" class="ui-textbox" value="${prjId}">
			                         <input name="businessType" id="businessType" type="text" class="ui-textbox" value="${businessType}">
			                         <input name="prjTypCd" id="prjTypCd" type="text" class="ui-textbox" value="${prjTypCd}">
			                         <input name="prjNm" id="prjNm" type="text" class="ui-textbox" value="${prjNm}">
			                         <input name="orgName" id="orgName" type="text" class="ui-textbox" value="${orgName}">
			                         <!-- 以下参数为查看逾期需要 -->
			                         <input name="overdueAmt_sys" id="overdueAmt_sys" type="text" class="ui-textbox" value="">
			                         <input name="interestAmt_sys" id="interestAmt_sys" type="text" class="ui-textbox" value="">
			                         <input name="overdueAmt_back" id="overdueAmt_back" type="text" class="ui-textbox" value="">
			                         <input name="interestAmt_back" id="interestAmt_back" type="text" class="ui-textbox" value="">

                                     <input name="cstStlIrr" id="cstStlIrr" type="text" class="ui-textbox" value="">
                                     <input name="redeemAmt" id="redeemAmt" type="text" class="ui-textbox" value="">
                                     <input name="discountAmt" id="discountAmt" type="text" class="ui-textbox" value="">
			                    </div>
			                </div>
						</div>
						<div class="btnsBox">
							<span id="saveAssRedeemCarBtn" class="sq-button sq-button-round" onclick="saveAssRedeemCar()">发起申请</span>
							<span id="closeBtn" class="sq-button sq-button-round" onclick="Remove_navTab()">关闭</span>
						</div>
					</form>
				</div>
				<!-- 页签2：拖车单信息 -->
				<div tabid="tabB" title="拖车单信息" id="tabBId" style="dis">
					<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
				</div>
			</div>
		</div>
	</div>

    <script>
	    var pageInApp={
			flag:false //tab页验证关闭
		};//to下一级子窗口 接口
		var pageInTab=null;//页签

        var redeemId = "${redeemId}";

	    $(function() {
	    	initForm();//初始化表单
	        initTab();//初始化页签
	        initData();//初始化数据
	        initMoneyData();//初始化数据
	        setDisplayData();//设置显示数据
	    	// loadFilesLiger("tcsh", 1, $("#redeem_Id").val());//加载文件列表信息
            // initRedeemFileGrid();
	    });

	    function changeFileGrid() {
	        var redeemTypCd = $("#redeemTypeCd").val();
	        initRedeemFileGrid(redeemTypCd);
        }

        var redeemFileGrid = null;

        // 维护过户方案资料Grid
        function initRedeemFileGrid(redeemTypCd) {
            redeemFileGrid = $("#redeemFileGrid").ligerGrid({
                url: '<%=path%>/ass/assDealRedeem/initRedeemFileGrid.do?id=' + redeemId + '&cfgCd=ASS009' + '&redeemTypCd=' + redeemTypCd,
                method: 'get',
                columns: [
                    {display: '资料名称', name: 'datNm', align: 'center', minWidth: 100, enabledSort: false},
                    {
                        display: '上传文件名称', name: 'fileNm', minWidth: 100, enabledSort: false,
                        render: function (rowdata, rowindex, value) {
                            if (value) {
                                var h;
                                h = '<a href="javascript:downloadFileByUrl(';
                                h += "'" + rowdata.filePath + "'";
                                h += ",'" + rowdata.fileNm + "'";
                                h += ')">' + rowdata.fileNm + '</a>'
                                return h;
                            }
                        }
                    },
                    {
                        display: '上传时间',
                        name: 'crtTm',
                        align: 'center',
                        width: 150,
                        enabledSort: false,
                        render: renderDate
                    },
                    {
                        display: '操作', name: 'operate', minWidth: 100, align: 'center', enabledSort: false,
                        render: function (rowdata, rowindex, value) {
                            var h = '';
                            h += '<a class="sq-button-hasicon uploadFile" style="cursor:pointer;" onclick="uploadFile(\'' + rowdata.cfgCd + '\', \'' + rowdata.cfgDtlCd + '\')"><i class="sqBtnIco_9"></i>上传</a><span class="sq-button sq-button-round fileupload-button" style="display: none;">上传<input type="file" id="uploadInput_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '" multiple name="fileup_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '"' +
                                ' class="fileupload-input" onchange="onChangefile_multi(event,\'' + rowdata.cfgCd + '\',\'' + rowdata.cfgDtlCd + '\',\'' + rowdata.orgCd + '\');"></span>';
                            if ('' != rowdata.fileId && null != rowdata.fileId) {
                                h += '<a class="sq-button-hasicon delFile" id="delFile_' + rowdata.cfgDtlCd + '" style="cursor:pointer;" onclick="delFile(event,' + rowdata.fileId + ');"><i class="sqBtnIco_7"></i>删除</a>';
                            }
                            return h;
                        }
                    }
                ],
                root: 'rows',
                hideLoadButton: true,
                width: '100%',
                height: '80px',
                isScroll: false,
                rownumbers: true,  //显示序号
                checkbox: false,
                allowUnSelectRow: true,
                alternatingRow: false,
                frozen: false,
                usePager: false,
                onAfterShowData: function () {
                    $('#redeemFileGrid').rowspan('datNm');
                    $('#redeemFileGrid').rowspan('operate');
                },
            });
        }

        //下载文件方法
        function downloadFileByUrl(_url,_name){
            if(SQ.regs.img.test(_name)){
                SQ.imgPreview(_url, true);
            }else{
                window.open(_url);
            }
        }

        // 上传文件a标签链接到input标签上
        function uploadFile(cfgCd, cfgDtlCd) {
            document.getElementById("uploadInput_" + cfgCd + "_" + cfgDtlCd).click();
        }

        /**
         * 上传文件
         * @param e
         * @param cfgCd
         * @param cfgDtlCd
         * @param orgCd
         */
        function onChangefile_multi(e, cfgCd, cfgDtlCd, orgCd) {
            var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            var filePath = "";
            filePath = "assRedeemFile";
            $.ajaxFileUpload({
                url: '<%=path%>/system/sysulfilesrec/upload.do',
                secureuri: false,
                fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
                dataType: 'json',
                data: {filePath: filePath},
                success: function (msg) {
                    if (msg.success == 1) {
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            data: {
                                'fileParams': JSON.stringify(msg.data),
                                'id': redeemId,
                                'cfgCd': cfgCd,
                                'cfgDtlCd': cfgDtlCd,
                                'orgCd': orgCd
                            },
                            url: '<%=path%>/ass/assDealRedeem/uploadRedeemFile.do',
                            success: function (msg) {
                                if (msg.success == 1) {
                                    redeemFileGrid.reload();
                                } else {
                                    $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                                }
                                $.ligerDialog.hide();
                            }
                        });
                    } else {
                        wait_dialog.close();
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        };

        // 格式化时间
        function renderDate(rowdata, index, value) {
            var dateStr = "";
            if (null != value) {
                var date = new Date(value);
                dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
            }
            return dateStr;
        }
		
	  	//初始化表单
		function initForm(){
	    	$("#redeemCar").ligerForm({
				validate: true
			});//初始化表单
			$("#redeemCar").check_ligerFormEditor();//重新刷新页面动态字段
		};
	    
		//初始化Tab页签
		function initTab(){
			var crflag = "detail";//查看交接单
			pageInTab = $("#pageInTab").ligerTab({
				height: 'auto',
				contextmenu: false,
				minIframeHeight: GET_minIframeHeight(),
				onAfterSelectTabItem: function(tabid) {
					//获取拖车主表ID和明细表ID供其它页面使用
					var tcMasterId = $("#tcMasterId").val();
					var tcDetailId = $("#tcDetailId").val();
					if(tabid!="tabA"){
						if(!tcDetailId || !tcMasterId){
							$.ligerDialog.SQalert({content: "抱歉信息不存在！", SQ_type: "warning"});
							return false; //验证不通过，不执行以下代码
						}
					}
					switch (tabid){
						case "tabB":							
							pageInTab.setTabItemSrc(tabid, "<%=path%>/ass/assTrailCarM/toInfoViewPage.do?tcMasterId="+tcMasterId+"&tcDetailId="+tcDetailId+"&crflag="+crflag);
							break;
					}
					SetIframe_height();
				}
			});
			//设置页签
			$.extend(true, pageInApp, {
				pageInTab: pageInTab
			});
		};
		
		//初始化数据
	    function initData(){
	    	var paySchId = $("#enabledPaySchId").val();
	    	if(!paySchId)return;
	    	var wait_dialog= $.ligerDialog.SQalert({
	            content: LogUtils.LOG_CMM_LOADING,
	            SQ_type: "waitting",
	            onClose: function () {
	            }
	        });
	    	
	    	var _url = '<%=path%>/ass/assTrailCarD/getTrailCarApplyInfo.do';
	    	$.ajax({
	    		type: 'get',
	    		dataType:'json',
	    		data:{enabledPaySchId:paySchId, dataFlag:"2"},
	    		url: _url,
	    		success:function(msg){
	    			 wait_dialog.close();
	    			 if(msg.success == 1 && null != msg.data){
	    				 setData(msg.data);//设置数据
	    			 }else{
	    				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			 }
	    		}
	    	});
	    }
		
		//设置页面数据
	    function setData(data){
	    	var form = liger.get("redeemCar");//加载表单
	    	//设置合同额和融资额
			$("#contAmt").val(data[0].contAmt / 100);
			$("#actLsAmt").val(data[0].actLsAmt / 100);
			$("#depositBaseAmt").val(data[0].contAmt / 100);
			form.setData({
				overdueAmt: data[0].overdueAmt / 100, //逾期租金
				interestAmt: data[0].penaltyAmt / 100, //罚息
				overdueAmt_sys: data[0].overdueAmt / 100, //当前逾期租金
				interestAmt_sys: data[0].penaltyAmt / 100 //当前罚息
	    	});
			//加载日期插件
			$("#redeemTm").trigger("change");
	    }
		
	  	//初始化赎回逾期金额数据-根据赎回方式更改取值方式
	    function initMoneyData(){
	    	var paySchId = $("#paySchId").val();
	    	if(!paySchId){
	    		//$.ligerDialog.SQalert({content: "支付表ID为空,无法查询相关信息！",SQ_type: "error"});
	    		return;
	    	}else{
		    	//加载拖车实际明细信息
		    	var _url = '<%=path%>/ass/assTrailCarDInf/getMoneyByPaySchId.do';
		    	$.ajax({
		    		type: 'get',
		    		dataType:'json',
		    		data:{paySchId:paySchId},
		    		url: _url,
		    		success:function(msg){
		    			 if(msg.success == 1){
		    				 setMoneyData(msg.data);//设置数据
		    			 }else{
		    				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
		    			 }
		    		}
		    	});
	    	}
	    }
	    
	    //设置实际拖回日期当天的逾期
	    function setMoneyData(data){
	    	//加载表单
	    	var form1 = liger.get("redeemCar");
	    	form1.setData({
				overdueAmt_back: data.overRentAmt / 100, //拖回日期当天逾期租金
				interestAmt_back: data.overInterestAmt / 100//拖回日期当天罚息
	    	});
            $("#redeemAmt").val(anyString(data.baseAmt / 100,2));//保留2位
            var _url = '<%=path%>/ass/assTrailCarD/calcCstStlIrrAndDiscountAmt.do';
            var paySchId = $("#enabledPaySchId").val();
            $.ajax({
                type: 'get',
                dataType:'json',
                data:{redeemId:'${redeem_Id}', paySchId:paySchId, redeemAmt:data.baseAmt, calcType: "1"},
                url: _url,
                success:function(msg){
                    if(msg.success == 1){
                        var discountAmt = msg.data.discountAmt;
                        var cstStlIrr = msg.data.cstStlIrr;
                        // 应收金额 = 保底价(赎回金额) - 结清优惠金额1
                        var receivableAmt = data.baseAmt - discountAmt;
                        $("#receivableAmt").val(anyString(receivableAmt / 100, 2));//保留2位
                        $("#cstStlIrr").val(cstStlIrr);
                        $("#discountAmt").val(discountAmt);
                    }else{
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
	    }
	    
	  	//设置显示数据
		function setDisplayData(){
			$("#redeemTypeCd").change(function(event) {
	            var redeemTypeCd=$(this).val();
	            var form2 = liger.get("redeemCar");
	            var overdueAmt = 0;
	            var interestAmt = 0;
	            var receiableAmt = 0;
	            if (redeemTypeCd == "1") {//赎回结清-取值时间节点为"实际拖回时间"
	            	overdueAmt = $("#overdueAmt_back").val();
	            	interestAmt = $("#interestAmt_back").val();
	            	receiableAmt = $("#redeemAmt").val() - $("#discountAmt").val();
	            }else {//赎回转正常-取值时间节点为"申请时间"开始
	            	overdueAmt = $("#overdueAmt_sys").val();
	            	interestAmt = $("#interestAmt_sys").val();
	            	receiableAmt = $("#redeemAmt").val();
	            }
	            //设置数据
		    	form2.setData({
					overdueAmt: overdueAmt, //逾期租金
					interestAmt: interestAmt, //罚息
                    receiableAmt: receiableAmt // 应收款金额
		    	});
	        });
		}

		//保存赎回申请信息（赎回信息主表）
		function saveAssRedeemCar(){
			$.ligerDialog.confirm('确定发起流程吗?', function (flag) {
				if(flag == false)return;
				var ligerForm = liger.get("redeemCar");
				if (!ligerForm.valid()) {
					top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
					return false; //验证不通过，不执行以下代码
				}
				//获取拖车信息明细表ID-为空提示
				var tcDetailId = $("#tcDetailId").val();
				if(!tcDetailId){
					top.$.ligerDialog.SQalert({content: "拖车明细信息不存在,不能发起赎回流程！",SQ_type: "warning"});
					return false;
				}
                var redeemTypeCd = $("#redeemTypeCd").val();//赎回方式
				if(redeemTypeCd == " "){
					top.$.ligerDialog.SQalert({content: "赎回方式为空,不能发起赎回流程！",SQ_type: "warning"});
					return false;
				}
                var row = redeemFileGrid.getRow(0);
                if (null == row.fileId && "1" == redeemTypeCd) {
                    top.$.ligerDialog.SQalert({content: "请上传《(赎回结清)提前结清协议书》",SQ_type: "error"});
                    return false;
                } else if (null == row.fileId && "2" == redeemTypeCd) {
                    top.$.ligerDialog.SQalert({content: "请上传《(赎回转正常)继续履行补充协议》",SQ_type: "error"});
                    return false;
                }
				//获取表单数据
				var data = ligerForm.getData();
				data["redeemId"] = redeemId;
				// console.log(data);
				//新增赎回信息主表数据
				var wait_dialog = null;
				var url = '<%=path%>/ass/assTrailCarD/addRedeemInfo.do';
				$.ajax({
					type: 'post',
					dataType: 'json',
					data: data,
					url: url,
					beforeSend: function(){
						wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(msg){
						wait_dialog.close();
						//返回的赎回信息主表ID不为空执行一下操作
						if(msg.success == 1 && null != msg.data){
                            top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
                            Remove_navTab();//关闭申请窗口
						}else{
							top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
						}
					}
				});
			});
			
		}
		
		//根据所选获取是合同额还是融资额
		function getTopric(typeId){
			var type = $("#"+typeId).val();
			if(type=="2"){
				return $("#actLsAmt").val();
			}else{
				return $("#contAmt").val();
			}
		}

		//计算赎回金额
		function planRedeemMoney(){
			var value1 = $("#depositAmt").val();//赎回保证金
			var value2 = $("#overdueAmt").val();//赎回逾期租金
			var value3 = $("#interestAmt").val();//赎回罚息
			var value4 = $("#actPayBackAmt").val();//实际付款金额(实际支付拖车费用)
			if(value4 == '' || value4==undefined){
				value4=0;
			}
			if(value1=='' || value1==undefined){
				value1=0;
			}
			//开始计算赎回金额
			var redeemMoney = 0;
			if(value1!='' && value2!='' && value3!=''){
				redeemMoney = parseFloat(value1)+parseFloat(value2)+parseFloat(value3)+parseFloat(value4);
			}else if(value1!='' && value2!=''){
				redeemMoney = parseFloat(value1)+parseFloat(value2)+parseFloat(value4);
			}else if(value2!='' && value3!=''){
				redeemMoney = parseFloat(value2)+parseFloat(value3)+parseFloat(value4);
			}else if(value1!='' && value3!=''){
				redeemMoney = parseFloat(value1)+parseFloat(value3)+parseFloat(value4);
			}else if(value1!=''){
				redeemMoney = parseFloat(value1)+parseFloat(value4);
			}else if(value2!=''){
				redeemMoney = parseFloat(value2)+parseFloat(value4);
			}else if(value3!=''){
				redeemMoney = parseFloat(value3)+parseFloat(value4);
			}
			$("#redeemAmt").val(anyString(redeemMoney,2));//保留2位
		}
		
		//计算赎回保证金
		function planRedeemMargin(){
			var topric = getTopric('amtTypeCd');
			var redeemMarginPercent = $("#depositPct").val();
			if (redeemMarginPercent.length > 0) {
				//不执行操作
			}else{
				$.ligerDialog.SQalert({content: "赎回保证金比例不能为空！",SQ_type: "warning"});
				return false;
			}
			if (isNumber(redeemMarginPercent) || isDouble(redeemMarginPercent)) {
				$("#depositAmt").val(redeemMarginPercent * topric / 100);
				planRedeemMoney();
			} else {
				$.ligerDialog.SQalert({content: "你输入的手续费比例不正确！",SQ_type: "warning"});
				$("#depositPct").val('');
				$("#depositAmt").val('');
				return false;
			}
		}

		//计算赎回保证金比例
		function planRedeemMarginPercent(){
			var topric = getTopric('amtTypeCd');
			var redeemMargin = $("#depositAmt").val();
			if (redeemMargin.length > 0) {
				//不执行操作
			}else{
				$.ligerDialog.SQalert({content: "赎回保证金不能为空！",SQ_type: "warning"});
				return false;
			}
			if (isNumber(redeemMargin) || isDouble(redeemMargin)) {
				$("#depositPct").val(redeemMargin / topric * 100);
				planRedeemMoney();
			} else {
				$.ligerDialog.SQalert({content: "你输入的手续费比例不正确！",SQ_type: "warning"});
				$("#depositPct").val('');
				$("#depositAmt").val('');
				return false;
			}
		}

    </script>
</body>
</html>